package htmlsoup

import (
	"code.google.com/awwwe-browser/data"
	"net/url"
)

// SoupNode.statics.staticNameSpaces

// parts

type staticNameSpaces struct {
	namespaces map[string]string
}

func buildStaticNameSpaces() staticNameSpaces {
	var v staticNameSpaces
	v.namespaces = make(map[string]string)
	return v
}

// node statics

type nodeStatics struct {
	// this is the namespaces for the entire document
	// all docNodes staticNameSpaces points to the same staticNameSpaces
	rootSoupNode         *SoupNode
	documentNameSpaces   staticNameSpaces
	defaultNameSpace     string
	haveDefaultNameSpace bool
	baseURI, location    *url.URL
}

func newNodeStatics() *nodeStatics {
	var v nodeStatics
	v.documentNameSpaces = buildStaticNameSpaces()
	v.defaultNameSpace = data.EmptyString
	v.haveDefaultNameSpace = false
	return &v
}

func (thisSNS *staticNameSpaces) getNameSpaces() map[string]string {
	return thisSNS.namespaces
}

func (thisSNS *staticNameSpaces) containsURI(uri string) bool {
	// return is the uri is in the document namespaces
	for _, v := range thisSNS.namespaces {
		if v == uri {
			return true
		}
	}
	return false
}

func (thisSNS *staticNameSpaces) getPrefix(uri string) string {
	// return the document namespace prefix for this uri
	for k, v := range thisSNS.namespaces {
		if v == uri {
			return k
		}
	}
	return data.EmptyString
}

func (thisSNS *staticNameSpaces) set(prefix, uri string) {
	// set a new prefix - uri pair
	thisSNS.namespaces[prefix] = uri
}
